<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: Ziun
  Date: 2019/4/17
  Time: 10:17
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<style type="text/css">
    .deleteColor:hover{
        color: #FED137;
    }
</style>
<script type="text/javascript" src="../js/jquery-2.1.0.js"></script>
<script type="text/javascript">
    $(function () {
        //修改商品数量
        $(".number").on('input propertychange', function() {
            var dqshopNum=$(this);
            var shopNum=$(this).prev();	//得到最初的值
            var dhNumber=parseInt(dqshopNum.val());
            var shNumber=parseInt(shopNum.val());
            if(dqshopNum.val()>0){
                var shopId=$(this).next().val();	//得到修改的id
                $.post("/ServletCustomer",{"action":"updateNumber","shopId":shopId,"number":dhNumber},callbackUpdateNumber,"text");
                function callbackUpdateNumber(data) {
                    if(data=="true"){
                        if(shNumber>dhNumber){
                            slBianHuan=shNumber-dhNumber;
                        }else if(shNumber<dhNumber){
                            slBianHuan=dhNumber-shNumber;
                        }
                        shopNum.val(dhNumber);
                        showMoney();
                    }else {
                        alert("修改失败！服务器失去连接！");
                        dqshopNum.val(shNumber);
                    }
                }
            }else {
                alert("商品数不能小于1！");
                shopNum.val(1);
                dqshopNum.val(1);
            }
        });
    })
    //删除商品
    function deleteShop(s_id,tag) {
        if(confirm("您确定要删除吗？")){
            $.post("/ServletCustomer?action=shopDel","spId="+s_id,callbackDelshop,"text");
            function callbackDelshop(data) {
                if(data=="true"){
                    $(tag).parent().remove();
                    alert("删除成功！");
                }else {
                    alert("删除失败！");
                }
            }
        }
    }
</script>
<body>
    <div>
        <table border="0px" width="95%"style="margin:30px;">
            <thead style="font-size: 16px;color:red;line-height:65px; text-align: center; ">
            <tr id="quanrentable_hang1">
                <td style="width:36%;text-align:left;">商品名</td>
                <td style="width:20%;">图片</td>
                <td style="width:8%;">原价</td>
                <td style="width:8%;">优惠价</td>
                <td style="width:8%;">打折</td>
                <td style="width:8%;">数量</td>
                <td style="width:8%;">操作</td>
            </tr>
            </thead>
            <c:forEach items="${ps.list}" var="cus" varStatus="i">
                <tr >
                    <td style="width:36%;text-align:left;">${cus.goodsName}</td>
                    <td style="width:20%;"><img src="GoodsImage/${cus.goodsImage}" style="width: 80px;height: 80px" ></td>
                    <td style="width:8%;">${cus.goodsMoney}</td>
                    <td style="width:8%;">${cus.discountPrice}</td>
                    <td style="width:8%;">${cus.discRate}</td>
                    <td style="width:8%;" ><input type="hidden" value="${cus.scNumber}"><input class="number" type="number" value="${cus.scNumber}"><input type="hidden" value="${cus.id}"></td>
                    <td style="width:8%;"  onclick="deleteShop(${cus.id},this)"><a class="deleteColor">删除</a></td>
                    <input type="hidden" value="${cus.goodsCarriage}"/>
                </tr>
            </c:forEach>
            <tr>
                <td colspan="7">
                    <jsp:include page="Page.jsp"/>
                </td>
            </tr>
        </table>
    </div>
</body>
</html>
